package com.ruoyi.demo.controller;

import java.math.BigDecimal;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ruoyi.SpringWebSocket.MyWsHandler;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.messages.service.ISysNotifyService;
import com.ruoyi.messages.service.impl.SysNotifyServiceImpl;
import com.ruoyi.orderParent.domain.SysOrder;
import org.apache.commons.collections4.Get;
import org.springframework.http.HttpRequest;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.demo.domain.Userdemo;
import com.ruoyi.demo.service.IUserdemoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 测试数据隔离Controller
 *
 * @author ruoyi
 * @date 2024-06-12
 */
@RestController
@RequestMapping("/demo/userdemo")
public class UserdemoController extends BaseController
{
    @Autowired
    private IUserdemoService userdemoService;

    @Autowired
    private MyWsHandler myWsHandler;

    @Autowired
    private SysNotifyServiceImpl notifyService;

    /**
     * 查询测试数据隔离列表
     */
    @PreAuthorize("@ss.hasPermi('demo:userdemo:list')")
    @GetMapping("/list")
    public TableDataInfo list(Userdemo userdemo)
    {
        startPage();
        List<Userdemo> list = userdemoService.selectUserdemoList(userdemo);
        return getDataTable(list);
    }

    /**
     * 导出测试数据隔离列表
     */
    @PreAuthorize("@ss.hasPermi('demo:userdemo:export')")
    @Log(title = "测试数据隔离", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Userdemo userdemo, HttpSession session)
    {
        List<Userdemo> list = userdemoService.selectUserdemoList(userdemo);
        ExcelUtil<Userdemo> util = new ExcelUtil<Userdemo>(Userdemo.class);
        util.exportExcel(response, list, "测试数据隔离数据");
    }

    /**
     * 获取测试数据隔离详细信息
     */
    @PreAuthorize("@ss.hasPermi('demo:userdemo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userdemoService.selectUserdemoById(id));
    }

    /**
     * 新增测试数据隔离
     */
    @PreAuthorize("@ss.hasPermi('demo:userdemo:add')")
    @Log(title = "测试数据隔离", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Userdemo userdemo)
    {
        return toAjax(userdemoService.insertUserdemo(userdemo));
    }

    /**
     * 修改测试数据隔离
     */
    @PreAuthorize("@ss.hasPermi('demo:userdemo:edit')")
    @Log(title = "测试数据隔离", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Userdemo userdemo)
    {
        return toAjax(userdemoService.updateUserdemo(userdemo));
    }

    /**
     * 删除测试数据隔离
     */
    @PreAuthorize("@ss.hasPermi('demo:userdemo:remove')")
    @Log(title = "测试数据隔离", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userdemoService.deleteUserdemoByIds(ids));
    }


    @Anonymous
    @GetMapping("/testBalance")
    public AjaxResult testBalance() {
//        notifyService.CheckStorePrice(243l);

        return success();
    }

    @Anonymous
    @GetMapping("/testOneOrder")
    public AjaxResult testOneOrder() {
        SysOrder sysOrder = new SysOrder();
        sysOrder.setAgentId(0l);
        sysOrder.setAmount(new BigDecimal(200));
        sysOrder.setDeptId(243l);
        sysOrder.setUserId(1l);
        sysOrder.setNumber("2024XX0628TT123");
        sysOrder.setCdName("张三");
        sysOrder.setId(100l);

        sysOrder.setIdNumber("141124200301000036");
        sysOrder.setPhone("13654889654");
        sysOrder.setAuthorizationType(0L);
        sysOrder.setPayStatus(0L);
        sysOrder.setOrderStatus(0l);
        sysOrder.setOrderOutcome(1l);
        sysOrder.setStoreName("管理员店铺");
        sysOrder.setAgentId(0l);
        sysOrder.setStoreId(243l);
//        notifyService.MakeOrder(sysOrder);
        return success();
    }
}
